<template>
	<view class="setting">
		<view class="contentBox">
			<view class="content-tit">
				绑定点三方账号
			</view>
			<view class="">
				<view class="binding-zh">
					<view class="binding-content">
						<image class="logo-icon" src="@/static/loginImg/meituan.png" mode=""></image>
						<view class="small-tit" v-if="isbind">
							<text style="line-height: 100rpx;">{{mtAcctount}}</text>
							<view>美团账号 已绑定</view>
						</view>
						<view class="small-tit" v-if="!isbind">
							<view @click="toggal" style="line-height: 150rpx; margin-left: 100rpx; width: 350rpx;">
								点击绑定美团账号
							</view>
						</view>
					</view>
					<image class="arrows"
						:src="arrowDown ? '../../../static/img/xiajt.png' : '../../../static/img/shangjt.png'"
						@click="toggal">
					</image>
				</view>
				<view class="setPwd" v-if="isShow">
					<view class="zhanghao">
						<text>账号：</text>
						<input class="input" type="text" />
					</view>
					<view class="zhanghao">
						<text>密码：</text>
						<input v-model="mtPwd" class="input" :type="pwd" />
						<image class="eyes" style="z-index: 999;"
							:src="isEyes ? '../../../static/loginImg/open-eyes.png' : '../../../static/loginImg/close-eyes.png'"
							@click="toggalEyes">
						</image>
					</view>
					<view class="zhanghao">
						<text>手机号：</text>
						<input v-model="mtAcctount" class="input" type="text" maxlength="11" />
					</view>
					<button @click="changeBtn" class="save-btn">保存更改</button>
				</view>
			</view>
			<view class="">
				<view class="binding-zh" style="background-color: #a7a3f7;">
					<view class="binding-content">
						<image class="logo-icon" src="@/static/loginImg/xiecheng.png"></image>
						<view class="small-tit" v-if="isbindXc">
							<text style="line-height: 100rpx;">{{xcAccount}}</text>
							<view>携程账号 已绑定</view>
						</view>
						<view class="small-tit" v-if="!isbindXc">
							<view @click="toggalXc" style="line-height: 150rpx; margin-left: 100rpx; width: 350rpx;">
								点击绑定携程账号</view>
						</view>
					</view>
					<image class="arrows"
						:src="arrowDownXc ? '../../../static/img/xiajt.png' : '../../../static/img/shangjt.png'"
						@click="toggalXc">
					</image>
				</view>
				<view class="setPwd" v-if="isShowXc">
					<view class="zhanghao">
						<text>账号：</text>
						<input class="input" type="text" />
					</view>
					<view class="zhanghao">
						<text>密码：</text>
						<input v-model="xcPwd" class="input" :type="pwd" />
						<image class="eyes" style="z-index: 999;"
							:src="isEyes ? '../../../static/loginImg/open-eyes.png' : '../../../static/loginImg/close-eyes.png'"
							@click="toggalEyes">
						</image>
					</view>
					<view class="zhanghao">
						<text>手机号：</text>
						<input v-model="xcAccount" class="input" type="text" maxlength="11" />
					</view>
					<button @click="bindXcBtn" class="save-btn">保存更改</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		bindingThird
	} from '@/api/user.js'
	export default {
		data() {
			return {
				isShow: false, //是否显示下拉列表
				isShowXc: false, //是否显示携程下拉列表
				arrowDown: true, // 新增一个变量来控制箭头方向
				arrowDownXc: true, //携程箭头
				isEyes: true, //是否点开眼睛
				pwd: 'password', //密码是否可见
				isbind: false, //是否已绑定美团手机号
				isbindXc: false, //是否已绑定携程手机号
				mtAcctount: '', //美团账号
				mtPwd: '', //美团密码
				xcAccount: '', //携程手机号
				xcPwd: '', //携程密码
			}
		},
		methods: {
			// 绑定美团
			async changeBtn() {
				if (!/^1[3456789]\d{9}$/.test(this.mtAcctount)) {
					uni.showToast({
						title: '请输入正确的手机号',
						icon: 'none'
					});
					return false;
				}
				console.log('美团', this.mtAcctount)
				if (!/^(?=.*[a-zA-Z])(?=.*\d).{6,}$/.test(this.mtPwd)) {
					uni.showToast({
						title: '至少包含密码由6个字母和数字',
						icon: 'none'
					});
					return false;
				}
				let params = {
					account: this.mtAcctount,
					password: this.mtPwd,
					platform: "美团"
				}
				await bindingThird(params).then(res => {
					console.log('数据', res)
					this.isbind = true
					uni.showToast({
						title: "绑定成功",
						icon: "none"
					})
				})
			},

			// 绑定携程
			async bindXcBtn() {
				if (!/^1[3456789]\d{9}$/.test(this.xcAccount)) {
					uni.showToast({
						title: '请输入正确的手机号',
						icon: 'none'
					});
					return false;
				}
				console.log('美团', this.xcAccount)
				if (!/^(?=.*[a-zA-Z])(?=.*\d).{6,}$/.test(this.xcPwd)) {
					uni.showToast({
						title: '至少包含密码由6个字母和数字',
						icon: 'none'
					});
					return false;
				}
				let params = {
					account: this.xcAccount,
					password: this.xcPwd,
					platform: "携程"
				}
				await bindingThird(params).then(res => {
					this.isbindXc = true
					uni.showToast({
						title: "绑定成功",
						icon: "none"
					})
				})
			},

			//切换眼睛
			toggalEyes() {
				console.log("sddddddd")
				this.isEyes = !this.isEyes
				if (this.isEyes) {
					this.pwd = 'password'
				} else {
					this.pwd = 'text'
				}
			},
			//美团切换
			toggal() {
				this.isShow = !this.isShow
				this.arrowDown = !this.arrowDown; // 切换箭头方向
				this.isShowXc = false; // 关闭携程下拉列表
			},
			//携程
			toggalXc() {
				this.isShowXc = !this.isShowXc
				this.isShow = false; // 关闭美团下拉列表
				this.arrowDownXc = !this.arrowDownXc; // 切换箭头方向
			}
		}
	}
</script>

<style lang="scss" scoped>
	.setting {
		width: 100%;
		height: 100vh;
		padding: 20rpx;
		background-color: #ffe1c2;

		.contentBox {
			display: flex;
			flex-direction: column;
			width: 100%;
			height: 500px;
			margin-top: 20rpx;
			padding: 20rpx;
			background-color: #fff0df;
			border-radius: 20rpx;
			box-shadow: 1rpx 5rpx 5rpx rgba(0, 0, 0, .2);

			.content-tit {
				width: 100%;
				height: 100rpx;
				font-weight: 700;
				line-height: 100rpx;
				font-size: 40rpx;
				text-align: center;
				color: #333;
			}

			.binding-zh {
				width: 100%;
				height: 200rpx;
				display: flex;
				align-items: center;
				border-radius: 20rpx;
				padding: 20rpx;
				margin-top: 20rpx;
				justify-content: space-between;
				background-color: #fdd74c;
				// margin-bottom: 20rpx;

				.binding-content {
					width: 70%;
					display: flex;
					flex-direction: row;
					align-items: center;

					.logo-icon {
						width: 120rpx;
						height: 120rpx;
						display: block;
					}

					.small-tit {
						width: 250rpx;
						height: 150rpx;
						font-size: 28rpx;
						margin-left: 20rpx;
					}
				}
			}

			.setPwd {
				width: 100%;
				height: 350rpx;
				justify-content: space-between;
				padding: 20rpx;
				margin-bottom: 20rpx;
				transition: height 0.8s ease;
				overflow: hidden;

				.zhanghao {
					position: relative;
					width: 90%;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.input {
						width: 400rpx;
						height: 60rpx;
						line-height: 60rpx;
						display: inline-block;
						margin-top: 20rpx;
						padding: 0 20rpx;
						border-radius: 10rpx;
						background-color: #fffbf6;
					}

					.eyes {
						position: absolute;
						width: 50rpx;
						height: 50rpx;
						right: 10rpx;
						top: 50%;
						transform: translateY(-35%);
					}
				}

				.save-btn {
					width: 350rpx;
					height: 60rpx;
					margin-left: 130rpx;
					margin-top: 20rpx;
					text-align: center;
					line-height: 60rpx;
					font-size: 28rpx;
					background-color: #ff9191;
				}
			}

			.arrows {
				width: 60rpx;
				height: 60rpx;
			}
		}
	}
</style>